package com.xiaoyang.orderservice.controller;

import com.xiaoyang.orderservice.domain.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.Date;

/**
 * @auther XiaoYang
 * @DATE 2023/5/5-8:46
 * 三种传参
 *  1、url：  /doOrder/热干面/add/油条/    @PathVariable
 *  2、 get传递一个参数
 *      get传递搓个参数
 *  3、 post传递一个对象
 *      post传递一个对象+一个基本参数
 *      post传递两个对象
 */
@Slf4j
@RestController
public class ParamController {

    @GetMapping("/testUrl/{name}/and/{age}")
    public String testUrl(@PathVariable String name,
                          @PathVariable Integer age){
        log.info("{}:{}",name,age);
        return "ok";
    }

    @GetMapping("/oneParam")//@RequestParam默认需要必须传参数才可以 这样写 可以传也可以不传
    public String oneParam(@RequestParam(required = false) String name){
        log.info("{}",name);
        return "ok";
    }

    @GetMapping("/twoParam")
    public String twoParam(@RequestParam(required = false) String name,
                           @RequestParam(required = false) Integer age){
        log.info("{}:{}",name,age);
        return "ok";
    }

    @PostMapping("/oneObj")
    public String oneObj(@RequestBody Order order){
        log.info("{}",order);
        return "ok";
    }

    @PostMapping("/oneObjOneParam")
    public String oneObjOneParam(@RequestBody Order order,
                                 @RequestParam("name") String name){
        log.info("{}:{}",order,name);
        return "ok";
    }

    //单独传递时间对象
    @GetMapping("/testTime")
    public String testTime(@RequestParam Date date){
        log.info("{}",date);
        return "ok";
    }

}
